home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 60 / IOPROG_60.ISO / soft / c++ / gsl-1.1.1-setup.exe / {app} / include / gsl / gsl_poly.h < prev    next >
Encoding:
C/C++ Source or Header  |  2002-04-20  |  3.5 KB  |  133 lines

  1. /* poly/gsl_poly.h
  2.  * 
  3.  * Copyright (C) 1996, 1997, 1998, 1999, 2000 Brian Gough
  4.  * 
  5.  * This program is free software; you can redistribute it and/or modify
  6.  * it under the terms of the GNU General Public License as published by
  7.  * the Free Software Foundation; either version 2 of the License, or (at
  8.  * your option) any later version.
  9.  * 
  10.  * This program is distributed in the hope that it will be useful, but
  11.  * WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  13.  * General Public License for more details.
  14.  * 
  15.  * You should have received a copy of the GNU General Public License
  16.  * along with this program; if not, write to the Free Software
  17.  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18.  */
  19.  
  20. #ifndef __GSL_POLY_H__
  21. #define __GSL_POLY_H__
  22.  
  23. #include <stdlib.h>
  24. #include <gsl/gsl_complex.h>
  25.  
  26. #undef __BEGIN_DECLS
  27. #undef __END_DECLS
  28. #ifdef __cplusplus
  29. # define __BEGIN_DECLS extern "C" {
  30. # define __END_DECLS }
  31. #else
  32. # define __BEGIN_DECLS /* empty */
  33. # define __END_DECLS /* empty */
  34. #endif
  35.  
  36. __BEGIN_DECLS
  37.  
  38.  
  39. /* Evaluate polynomial
  40.  *
  41.  * c[0] + c[1] x + c[2] x^2 + ... + c[len-1] x^(len-1)
  42.  *
  43.  * exceptions: none
  44.  */
  45. double gsl_poly_eval(const double c[], const int len, const double x);
  46.  
  47.  
  48. #ifdef HAVE_INLINE
  49. extern inline
  50. double gsl_poly_eval(const double c[], const int len, const double x)
  51. {
  52.   int i;
  53.   double ans = c[len-1];
  54.   for(i=len-1; i>0; i--) ans = c[i-1] + x * ans;
  55.   return ans;
  56. }
  57. #endif /* HAVE_INLINE */
  58.  
  59. /* Work with divided-difference polynomials, Abramowitz & Stegun 25.2.26 */
  60.  
  61. int
  62. gsl_poly_dd_init (double dd[], const double x[], const double y[],
  63.                   size_t size);
  64.  
  65. double
  66. gsl_poly_dd_eval (const double dd[], const double xa[], const size_t size, const double x);
  67.  
  68. #ifdef HAVE_INLINE
  69. extern inline
  70. double gsl_poly_dd_eval(const double dd[], const double xa[], const size_t size, const double x)
  71. {
  72.   size_t i;
  73.   double y = dd[size - 1];
  74.   for (i = size - 1; i--;) y = dd[i] + (x - xa[i]) * y;
  75.   return y;
  76. }
  77. #endif /* HAVE_INLINE */
  78.  
  79.  
  80. int
  81. gsl_poly_dd_taylor (double c[], double xp,
  82.                     const double dd[], const double x[], size_t size,
  83.                     double w[]);
  84.  
  85. /* Solve for real or complex roots of the standard quadratic equation,
  86.  * returning the number of real roots.
  87.  *
  88.  * Roots are returned ordered.
  89.  */
  90. int gsl_poly_solve_quadratic (double a, double b, double c, 
  91.                   double * x0, double * x1);
  92.  
  93. int 
  94. gsl_poly_complex_solve_quadratic (double a, double b, double c, 
  95.                   gsl_complex * z0, gsl_complex * z1);
  96.  
  97.  
  98. /* Solve for real roots of the cubic equation
  99.  * x^3 + a x^2 + b x + c = 0, returning the
  100.  * number of real roots.
  101.  *
  102.  * Roots are returned ordered.
  103.  */
  104. int gsl_poly_solve_cubic (double a, double b, double c, 
  105.               double * x0, double * x1, double * x2);
  106.  
  107. int 
  108. gsl_poly_complex_solve_cubic (double a, double b, double c, 
  109.                   gsl_complex * z0, gsl_complex * z1, 
  110.                   gsl_complex * z2);
  111.  
  112.  
  113. /* Solve for the complex roots of a general real polynomial */
  114.  
  115. typedef struct 
  116.   size_t nc ;
  117.   double * matrix ; 
  118. gsl_poly_complex_workspace ;
  119.  
  120. gsl_poly_complex_workspace * gsl_poly_complex_workspace_alloc (size_t n);
  121. void gsl_poly_complex_workspace_free (gsl_poly_complex_workspace * w);
  122.  
  123. int
  124. gsl_poly_complex_solve (const double * a, size_t n, 
  125.                         gsl_poly_complex_workspace * w,
  126.                         gsl_complex_packed_ptr z);
  127.  
  128. __END_DECLS
  129.  
  130. #endif /* __GSL_POLY_H__ */
  131.